package com.cosina.game.colorball;

import java.util.ArrayList;
import java.util.List;

import com.cosina.game.BallGameStartActivity;

import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;

public class Trophy {
	
	private static SharedPreferences sp;
	public static void init(Context context){
		sp = context.getSharedPreferences(BallGameStartActivity.PREFERENCE_FILE_NAME, Context.MODE_PRIVATE);
	}
	
	public static boolean isBrokenRecord(int score,Difficulty difficulty){
		return score > sp.getInt(difficulty + BallGameStartActivity.PREFERENCE_RECORD, 0);
	}
	
	public static void saveBrokenRecord(int score, String recordBreaker,Difficulty difficulty){
		sp.edit()
		.putInt(difficulty + BallGameStartActivity.PREFERENCE_RECORD, score)
		.putString(difficulty + BallGameStartActivity.PREFERENCE_BREAKER, recordBreaker)
		.commit();
	}
	public static void showRecord(Context context){
		 AlertDialog.Builder recordDialog = new AlertDialog.Builder(context);
		 recordDialog.setTitle("Ball Game Record");
		 List<String> items = new ArrayList<String>();
		 for(int i=3; i<6; i++){
			 String recordScore = sp.getString(i + BallGameStartActivity.PREFERENCE_RECORD, "0");
			 String name = sp.getString(i + BallGameStartActivity.PREFERENCE_BREAKER, "mr. UFO");
			 items.add(Difficulty.desc(i) + " : " + name  + " : " + recordScore);
		 }
		 recordDialog.setItems(items.toArray(new String[0]), null);
		 recordDialog.create().show();
	}
	
}
